package com.ruoyi.labsafety.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.labsafety.domain.LabSafetyCheckRelFile;
import com.ruoyi.labsafety.service.ILabSafetyCheckRelFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 安全检查附件Controller
 * 
 * @author ruoyi
 * @date 2022-03-30
 */
@RestController
@RequestMapping("/labsafety/file")
public class LabSafetyCheckRelFileController extends BaseController
{
    @Autowired
    private ILabSafetyCheckRelFileService labSafetyCheckRelFileService;

    /**
     * 查询安全检查附件列表
     */
   // @PreAuthorize("@ss.hasPermi('labsafety:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabSafetyCheckRelFile labSafetyCheckRelFile)
    {
        startPage();
        List<LabSafetyCheckRelFile> list = labSafetyCheckRelFileService.selectLabSafetyCheckRelFileList(labSafetyCheckRelFile);
        return getDataTable(list);
    }

    /**
     * 导出安全检查附件列表
     */
   // @PreAuthorize("@ss.hasPermi('labsafety:file:export')")
    @Log(title = "安全检查附件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LabSafetyCheckRelFile labSafetyCheckRelFile)
    {
        List<LabSafetyCheckRelFile> list = labSafetyCheckRelFileService.selectLabSafetyCheckRelFileList(labSafetyCheckRelFile);
        ExcelUtil<LabSafetyCheckRelFile> util = new ExcelUtil<LabSafetyCheckRelFile>(LabSafetyCheckRelFile.class);
        return util.exportExcel(list, "file");
    }

    /**
     * 获取安全检查附件详细信息
     */
  //  @PreAuthorize("@ss.hasPermi('labsafety:file:query')")
    @GetMapping(value = "/{projectRelFileId}")
    public AjaxResult getInfo(@PathVariable("projectRelFileId") Long projectRelFileId)
    {
        return AjaxResult.success(labSafetyCheckRelFileService.selectLabSafetyCheckRelFileById(projectRelFileId));
    }

    /**
     * 新增安全检查附件
     */
   // @PreAuthorize("@ss.hasPermi('labsafety:file:add')")
    @Log(title = "安全检查附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabSafetyCheckRelFile labSafetyCheckRelFile)
    {
        return toAjax(labSafetyCheckRelFileService.insertLabSafetyCheckRelFile(labSafetyCheckRelFile));
    }

    /**
     * 修改安全检查附件
     */
  //  @PreAuthorize("@ss.hasPermi('labsafety:file:edit')")
    @Log(title = "安全检查附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabSafetyCheckRelFile labSafetyCheckRelFile)
    {
        return toAjax(labSafetyCheckRelFileService.updateLabSafetyCheckRelFile(labSafetyCheckRelFile));
    }

    /**
     * 删除安全检查附件
     */
  //  @PreAuthorize("@ss.hasPermi('labsafety:file:remove')")
    @Log(title = "安全检查附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectRelFileIds}")
    public AjaxResult remove(@PathVariable Long[] projectRelFileIds)
    {
        return toAjax(labSafetyCheckRelFileService.deleteLabSafetyCheckRelFileByIds(projectRelFileIds));
    }
}
